package com.hdp.jetpack_mvvm.livedata

import androidx.lifecycle.LiveData
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel

/**
 * 用于系统杀死进程后的数据恢复
 */
class ViewModel3(private val savedStateHandle: SavedStateHandle) : ViewModel() {

    private val NAME_KEY = "name"

    fun getName(): LiveData<String> {
        return savedStateHandle.getLiveData(NAME_KEY)
    }

    fun saveNewName(newName: String) {
        savedStateHandle.set(NAME_KEY, newName)
    }

}